//
//  SignDataCenter.m
//  Safflower
//
//  Created by 袁亮 on 2016/12/26.
//  Copyright © 2016年 Migic_Z. All rights reserved.
//

#import "SignDataCenter.h"

@implementation SignDataCenter

- (void)fetchSignList:(NSString *)taskNumber complation:(void (^)(id, NSString *))complation
{
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"tasknumber":taskNumber,
                            @"user":[NSNumber numberWithInteger:user.userId]
                            };
    [HttpRequest POSTRequest:SignList WithParams:param WithSuccess:^(id responseOjbect) {
        
        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            NSArray *dataArray = (NSArray *)[responseOjbect objectForKey:@"data"];
            NSArray *modelArray = [NSArray yy_modelArrayWithClass:[SignModel class] json:dataArray];
            complation(modelArray, nil);
        }else{
            complation(nil,[responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(nil,@"服务器异常");
    }];
}

- (void)signinWithTask:(NSString *)taskNumber signImage:(UIImage *)image complation:(void (^)(NSString *))complation
{
    NSString *todayUnix = [ZZDateFormat fetchNowDateForUnix];
    NSString *todayDate = [ZZDateFormat fetchUnixDate:[ZZDateFormat fetch10Date:todayUnix format:@"yyyyMMdd"] format:@"yyyyMMdd"];
    
    UserModel *user = [UserManager fetchUserInfo];
    NSDictionary *param = @{
                            @"user":[NSNumber numberWithInteger:user.userId],
                            @"tasknumber":taskNumber,
                            @"today":todayDate,
                            @"imagebase":[UIImage imageToBase64String:image],
                            };
    [HttpRequest POSTRequest:SignIn WithParams:param WithSuccess:^(id responseOjbect) {

        if ([[responseOjbect objectForKey:@"code"] integerValue] == 1) {
            complation(nil);
        }else{
            complation([responseOjbect objectForKey:@"message"]);
        }
        
    } WithFail:^(NSError *error) {
        complation(@"服务器异常");
    }];
}

@end
